package cn.demoncat.util.mysql.entity;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述：代码生成-表
 *
 * @author yxl
 *
 * @version 2.0
 *
 * @since 2016年7月9日
 */
public class DbGenTable {

	// 表名
	private String name;
	// 表类名
	private String javaName;
	// 表注释
	private String comment;
	// 字段
	private List<DbGenField> fields = new ArrayList<>();
	// ID字段
	private DbGenField idField;

	public DbGenTable() {
		// 初始化ID字段：默认没有ID会报错，宽松场景用默认值来防止异常
		idField = new DbGenField();
		idField.setJdbcType("VARCHAR");
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public List<DbGenField> getFields() {
		return fields;
	}

	/**
	 * 设置字段
	 * @param fields
	 */
	public void setFields(List<DbGenField> fields) {
		// 所有字段
		this.fields = fields;
		for (DbGenField field : fields) {
			if (field.getName().equals("id")) {
				// id字段
				this.idField = field;
				break;
			}
		}
	}

	public String getJavaName() {
		return javaName;
	}

	public void setJavaName(String javaName) {
		this.javaName = javaName;
	}

	public DbGenField getIdField() {
		return idField;
	}

	public void setIdField(DbGenField idField) {
		this.idField = idField;
	}
}
